﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace LaserAutoTest.Common
{
    public class HttpHelper
    {
        public static async Task<HttpResponseMessage> HttpPostAsync(string filePath,string token,string url)
        {
            HttpClient httpClient = new HttpClient();
            var formData = new MultipartFormDataContent();
            formData.Add(new StreamContent(ReadFile(filePath)), "file", Path.GetFileName(filePath));
            formData.Add(new StringContent(token), "token");

            return await httpClient.PostAsync(url, formData);
        }

        private static FileStream ReadFile(string filePath)
        {
            var path = Path.Combine(Directory.GetCurrentDirectory(), filePath);
            return File.OpenRead(path);
        }
    }
}
